﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Yes.Application.Category;
using Yes.Application.Category.Dto;
using Yes.Domain.Entity;

namespace Yes.Web.Blog.Areas.Admin.Controllers
{
    [Area("Admin")]
    public class CategoryController : BaseController
    {
        private ICategoryService _categoryService;

        public CategoryController(ICategoryService categoryService)
        {
            _categoryService = categoryService;
        }

        public ActionResult Index()
        {
            var categoryList = _categoryService.GetCategoryList();
            return View(categoryList);
        }

        [HttpGet]
        public ActionResult Add(int id = 0)
        {
            var category = _categoryService.GetCategory(id) ?? new CategoryEntity()
            {
                Name = "",
                SortId = 99
            };
            return View(category);
        }

        [HttpPost]
        public ActionResult Add(CategoryAddDto dto)
        {
            return Json(_categoryService.AddCategory(dto));
        }

        [HttpPost]
        public ActionResult Delete(List<int> ids)
        {
            return Json(_categoryService.DeleteCategory(ids));
        }

        [HttpPost]
        public ActionResult UpdateOrder(List<int> ids, List<int> sortids)
        {
            return Json(_categoryService.UpdateOrder(ids, sortids));
        }
    }
}